#ifndef  CMD_KW_H
#define  CMD_KW_H

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sys/queue.h>

#ifdef __cplusplus
extern "C" {
#endif

#define  KW_FLAG_NULL   1
#define  KW_FLAG_INPUT  (1U << 1)

#define  KW_ARG_MAX     128

typedef void (*cmd_func_t)(void);

struct kw {
  uint32_t flag;
  const char *word;
  struct kw *sib;
  struct kw *son;
  cmd_func_t callback;
  int size;
};

struct kw_statement {
  const char *name;
  const char *templ;
  cmd_func_t func;
  STAILQ_ENTRY(kw_statement) entry;
};

void kw_add_statement(struct kw_statement *statement);

#define BOLT(n, t)                        \
  static void cmd_##n(void);              \
static struct kw_statement _kw_s_##n = {  \
    .name = #n,                           \
    .templ = t,                           \
    .func = cmd_##n,                      \
  };                                      \
  static void __attribute__((constructor)) _kw_fun_##n(void) {\
    kw_add_statement(&_kw_s_##n);         \
  }                                       \
  static void cmd_##n(void)
  
const char *pop_argz(void);
int cli_exit(void);
int cli_init(const char *prompt, const char *profile);
void cli_in_event(void *userdata);

#ifdef __cplusplus
}
#endif

#endif
